import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import ConfigElementType 1.0
import "qrc:/qmlComponents/ConfigManager"
import "qrc:/qmlComponents/AxisModulePos"
import "qrc:/qmlComponents/VisionViewer"
import "qrc:/qmlComponents/CustomizedUIElement"

Item {
    RowLayout{
        spacing: 30
        ColumnLayout{
            spacing: 10
            Layout.alignment: Qt.AlignTop

            ConfigRow{
                configName: "ltMagTrayCount"
                configModel: ltModuleConfig
                Component.onCompleted: {
                    init(ConfigElementType.Int)
                }
            }
            SAxisModulePos{
                moduleName: "LTMagZ"
                posName: "KickFirtTrayPos"
            }
            SAxisModulePos{
                moduleName: "LTMagZ"
                posName: "KickLastTrayPos"
            }
            SAxisModulePos{
                moduleName: "LTMagZ"
                posName: "RetrieveFirstTrayPos"
            }
            SAxisModulePos{
                moduleName: "LTMagZ"
                posName: "RetrieveLastTrayPos"
            }
            SAxisModulePos{
                moduleName: "LTMagZ"
                posName: "ChangeMagazinePos"
            }
        }

        ColumnLayout{
            spacing: 10
            Layout.alignment: Qt.AlignTop

            RowLayout{
                Label{
                    text: qsTr("TrayIndex:")
                }
                TextField{
                    id: txtTrayIndex
                    text: "0"
                    validator: IntValidator{}
                    implicitWidth: 80
                    selectByMouse: true
                }
            }

            RowLayout{
                Button{
                    text: qsTr("MoveToKickTrayPos")
                    onClicked: {
                        tem.runSingleCmd(lensTrayMagazine, "reqMoveToKickTrayPos", [txtTrayIndex.text])
                    }
                }
                Button{
                    text: qsTr("MoveToRetrieveTrayPos")
                    onClicked: {
                        tem.runSingleCmd(lensTrayMagazine, "reqMoveToRetrieveTrayPos", [txtTrayIndex.text])
                    }
                }
            }

            RowLayout{
                Button{
                    text: qsTr("KickTray")
                    onClicked: {
                        tem.runSingleCmd(lensTrayMagazine, "kickTray")
                    }
                }
                Button{
                    text: qsTr("RetractKicker")
                    onClicked: {
                        tem.runSingleCmd(lensTrayMagazine, "retractKicker")
                    }
                }
            }

            RowLayout{
                Button{
                    text: qsTr("MoveToNextRawTrayPos")
                    onClicked: {
                        lensTrayMagazine.handleDebugEvent("moveToNextRawTrayPos")
                    }
                }
                Button{
                    text: qsTr("MoveToFirstInUseTrayPos")
                    onClicked: {
                        lensTrayMagazine.handleDebugEvent("moveToFirstInUseTrayPos")
                    }
                }
            }

            Button{
                text: qsTr("ChangeMagazine")
                onClicked: {
                    tem.runMultiCmdsHasArg(lensTrayMagazine, [["setInLoadUnloadTrayLoopTestMode", false], ["changeMagazine"]])
                }
            }
            Button{
                text: qsTr("ResetMagTrayState")
                onClicked: {
                   tem.runSingleCmd(lensTrayMagazine, "resetMagTrayState")
                }
            }
        }
    }
}

